package org.emcode.sample.appleguice.client.mvp;

import net.customware.gwt.presenter.client.widget.WidgetDisplay;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class GreetingView extends Composite implements GreetingPresenter.Display {
	private final TextBox nameField;
	private final Button sendButton;
	private VerticalPanel vPanel;

	
	public GreetingView() {

		vPanel = new VerticalPanel();
		vPanel.setStyleName("centered-panel");
		
		// modify the title in the body and the window
		String us = "Apple Guice";
		HTMLPanel html = new HTMLPanel(us);
		html.setStyleName("title");
		RootPanel.get().add(html);
		Window.setTitle(us);
		
		// paragraph
		HTML description = new HTML("A demo App Engine application using GWT with MVP (via gwt-dispath and " +
				"gwt-presener), dependency injection (GIN on the client, Guice on the server)," +
				" and a sharded counter to track the number of visitors.");
		description.setStyleName("description");
		
		// create an image
		final Image image = new Image();
		image.setUrl("appleguice.png");
		image.setStyleName("logo");
		
		HorizontalPanel hp = new HorizontalPanel();
		sendButton = new Button("was here");
		nameField = new TextBox();
		nameField.setText("[type your name here]");
		hp.add(nameField);
		hp.add(sendButton);
		hp.setStyleName("centered-panel");

		// We can add style names to widgets
		sendButton.addStyleName("sendButton");
		
		// try init the widget
		vPanel.add(html);
		vPanel.add(image);
		vPanel.add(description);
		vPanel.add(hp);
		
		
		initWidget(vPanel);
		
		reset();
	}

	public HasValue<String> getName() {
		return nameField;
	}

	public HasClickHandlers getSend() {
		return sendButton;
	}
	
	public void reset() {
		// Focus the cursor on the name field when the app loads
		nameField.setFocus(true);
		nameField.selectAll();
	}

	/**
	 * Returns this widget as the {@link WidgetDisplay#asWidget()} value.
	 */
	public Widget asWidget() {
		return this;
	}

	public void startProcessing() {
	}

	public void stopProcessing() {
	}
}